const program = require("commander");
// 获取版本号
const version = require("../package.json").version;
program.version(version);
// 引入命令配置
const mapActions = require("./commander");
// 获取所有命令
let keys = [...Reflect.ownKeys(mapActions)];
// 引入工具
const { log, clear, showTitle } = require("./utils");

keys.forEach((key) => {
  program
    .command(key)
    .alias(mapActions[key].alias)
    .description(mapActions[key].description)
    .action(async () => {
      if (key === "*") {
        log("command not found", "red");
      } else {
        showTitle('XiongKe Cloud');
        log('欢迎使用熊客cli')
      }
    });
});

// log(showText)
// 监听help
program.on("--help", () => {
  log("\nExamples:", "red");
  keys.forEach((key) => {
    if (key === "*") return;
    console.log(`-- ${mapActions[key].description}:`);
    mapActions[key].examples.forEach((example) => {
      log(example, "blue");
    });
    log();
  });
});

// 解析进程参数
program.parse(process.argv);
